/*
 *  touchHell.m
 *  touchhell
 *
 *  Created by omega on 08/12/22.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#import "touchHell.h"
#import "Texture2D.h"
#import "EAGLView.h"
#import "SoundEngine.h"

UInt32 _sounds[HELL_SOUND_MAX];
Boolean hell_isBgmLoaded = NO;

// load texture
void Hell_loadTextureFromFile( int tex_idx , char* filename ) {
	NSString* filestr;
	filestr = [NSString stringWithCString:filename];
	_textures[ tex_idx ] = [[Texture2D alloc] initWithImage:[UIImage imageNamed:filestr]];
}

// draw with font
void Hell_drawFontWithTexture( int tex_idx , char* str ){
	[_textures[ tex_idx ] drawFontWithCString:str];
}

// draw tecture
void Hell_drawTexture( int tex_idx , float tx , float ty , float tw , float th ){
	[_textures[ tex_idx ] drawClipRect:CGRectMake( tx,ty,tw,th ) DestPoint:CGPointZero];
}

// draw line
void Hell_drawLine( float x1, float y1 , float x2, float y2 ){
}

float Hell_getAccelerometerX() {return _accelerate.x;}
float Hell_getAccelerometerY() {return _accelerate.y;}
float Hell_getAccelerometerZ() {return _accelerate.z;}

// SoundEngine wrapper
void Hell_loadSoundEffectFromFile( int snd_idx , char* filename ){
	NSBundle* bundle = [NSBundle mainBundle];
	NSMutableString* path = [NSMutableString stringWithString:[bundle resourcePath]];
	NSString* name = [[NSString alloc] initWithCString:filename];
	[path appendString:@"/"];
	[path appendString:name];
	NSLog( @"SoundEngine_loadEffect:%d" , SoundEngine_LoadEffect([path UTF8String] , &_sounds[snd_idx]));
	[name release];
}

void Hell_playSoundEffect( int snd_idx ){	
	SoundEngine_StartEffect( _sounds[snd_idx] );
}

void Hell_loadBgm( char* filename ){
	NSBundle* bundle = [NSBundle mainBundle];
	NSMutableString* path = [NSMutableString stringWithString:[bundle resourcePath]];
	NSString* name = [[NSString alloc] initWithCString:filename];
	[path appendString:@"/"];
	[path appendString:name];
	NSLog( @"SoundEngine_loadBackgroundMusicTrack:%d" , SoundEngine_LoadBackgroundMusicTrack([path UTF8String] , true , true ));
	[name release];
}

void Hell_playBgm(){
	SoundEngine_StartBackgroundMusic();
}

void Hell_stopBgm(){
	SoundEngine_StopBackgroundMusic( false );
}

void Hell_setBgmVolume( float volume ){
	SoundEngine_SetBackgroundMusicVolume( volume );
}